import * as Cesium from "cesium";
import { click } from "../";
import url from "../Axios/url.config";

const explosionViewer = (id: string): Cesium.Viewer => {
  const defaultAccessToken =
    "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJqdGkiOiI2YzRjYmVkZS1mYzVkLTRhNzQtOWQxNS00ODhkYjNiMTVhZjMiLCJpZCI6ODg4MCwiaWF0IjoxNjI5MDg0MjU5fQ.HjR32IeXm9JIf43_sIzuRBeIeJyf01VBLgeCdnTFyJw";
  Cesium.Ion.defaultAccessToken = defaultAccessToken;

  const viewer = new Cesium.Viewer(id, {
    scene3DOnly: false,
    selectionIndicator: false,
    infoBox: false,
    geocoder: false,
    homeButton: false,
    sceneModePicker: false,
    projectionPicker: false,
    baseLayerPicker: false,
    navigationHelpButton: false,
    animation: false,
    timeline: false,
    fullscreenButton: false,
    vrButton: false,
    skyBox: false,
    shouldAnimate: true,
  });

  viewer.imageryLayers.removeAll();
  viewer.imageryLayers.addImageryProvider(
    new Cesium.WebMapTileServiceImageryProvider({
      url: "http://{s}.tianditu.gov.cn/img_w/wmts?service=wmts&request=GetTile&version=1.0.0&LAYER=img&tileMatrixSet=w&TileMatrix={TileMatrix}&TileRow={TileRow}&TileCol={TileCol}&style=default&format=tiles&tk=e2b7c83f4a91dcb6974600b2f88de197",
      style: "default",
      layer: "img",
      format: "image/jpeg",
      tileMatrixSetID: "GoogleMapsCompatible",
      subdomains: ["t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7"],
      maximumLevel: 18,
    })
  );

  viewer.terrainProvider = new Cesium.CesiumTerrainProvider({
    url: Cesium.IonResource.fromAssetId(1),
  });

  // 液化空气
  viewer.scene.primitives.add(
    new Cesium.Cesium3DTileset({
      url: url.yhkq_model,
      maximumScreenSpaceError: 2,
      modelMatrix: new Cesium.Matrix4(
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        6.5,
        0.0,
        0.0,
        0.0,
        1.0
      ),
    })
  );

  // 锦湖金马
  viewer.scene.primitives.add(
    new Cesium.Cesium3DTileset({
      url: url.jhjm_model,
      maximumScreenSpaceError: 2,
      modelMatrix: new Cesium.Matrix4(
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        6.5,
        0.0,
        0.0,
        0.0,
        1.0
      ),
    })
  );

  // 广信化工
 let gx = viewer.scene.primitives.add(
    new Cesium.Cesium3DTileset({
      url: url.gxhg_model,
      maximumScreenSpaceError: 2,
      modelMatrix: new Cesium.Matrix4(
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        0.0,
        0.0,
        0.0,
        0.0,
        1.0,
        10.5,
        0.0,
        0.0,
        0.0,
        1.0
      ),
    })
  );

  viewer.scene.globe.depthTestAgainstTerrain = true;
  viewer.scene.globe.showGroundAtmosphere = false;

  viewer.cesiumWidget.creditContainer.remove();
  viewer.zoomTo(gx)

  // handle 取坐标
  click(viewer);
  return viewer;
};

export default explosionViewer;
